import React from 'react';
import { Route } from "react-router-dom";
// import RouterTitleReducer from '../reducer/RouterTitleReducer'

/**
 * 路由Route组件传入参数
 * 
 * @interface Props
 * path 路由地址
 * exact 默认false; true: 地址的 '/' 后 '?' 前 完全匹配 path
 * strict 默认false; true: 地址的 '/' 后 第二个 '/' 前 跟 path 必须匹配
 * component 跳转的对应组件
 * render 跳转之前的方法
 * 
 * retuen 路由 Route 组件，或者 render 方法跳出
 */

class ReduxRouter extends React.Component{

    routeRender = (props) => {
        let {component: Com, render} = this.props,
            matchUrl = props.match.url,
            pathName = props.location.pathname;
        // RouterTitleReducer.setUrlMap(matchUrl);
        if(matchUrl === pathName){
            // RouterTitleReducer.setCurPath(pathName);
        }
        if(Com){
            return <Com {...props} />
        }

        return render(props);
    }

    render() {
        let { path, exact = false, strict = false } = this.props;
        return(
            <Route
                path = {path}
                exact = {exact}
                strict = {strict}
                render = {this.routeRender}
            />
        )
        
    }
}

export default ReduxRouter